Skip to content

fix(redshift): escape SQL identifiers and literals in metadata/DDL paths (#1914) - #2203

Merged
openai0229 merged 5 commits into
OtterMind:mainfrom
HandSonic:fix/sqli2-redshift
Jul 29, 2026
Merged

fix(redshift): escape SQL identifiers and literals in metadata/DDL paths (#1914)#2203
openai0229 merged 5 commits into
OtterMind:mainfrom
HandSonic:fix/sqli2-redshift

Conversation

@HandSonic

@HandSonic HandSonic commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #1914

Summary

Completes the Redshift database-plugin portion of the identifier and literal escaping work.

  • Reuses the verified PostgreSQL identifier processor because Redshift has the same double-quote, case-folding, reserved-word, and string-literal rules.
  • Preserves exact raw identifier round trips, including empty strings and boundary or embedded double quotes.
  • Keeps SPI lookup/completion quoting conditional while retaining unconditional quoting for metadata-generated SQL.
  • Escapes SHOW CREATE TABLE schema/table names, supports an omitted schema, and rejects a missing table name.
  • Expands regression coverage for case folding, reserved words, quote/remove round trips, literal escaping, and adversarial metadata names.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results:
    • mvn -B -f chat2db-community-server/pom.xml -pl chat2db-community-plugins/chat2db-community-redshift -am -DskipTests=false -Dmaven.test.skip=false clean test
    • Result: BUILD SUCCESS across 9 reactor modules; 182 tests passed in tested modules, including Redshift 17/17, PostgreSQL 49/49, SPI 90/90, and tools 26/26.
    • git diff --check origin/main...HEAD: passed.
  • Manual verification: Source-level generated-SQL review completed. No live Redshift instance was used.
  • UI evidence: N/A

Risk and compatibility

  • Public API or stored data: No public API or stored-data schema change. Uses the existing shared ISQLIdentifierProcessor contract.
  • Database or driver compatibility: Redshift now follows the PostgreSQL processor already used by its inherited metadata and builder paths; ordinary lowercase identifiers stay conditional while mixed-case/reserved identifiers retain identity through quoting.
  • Network, privacy, or security: No network or privacy change. Reduces malformed SQL and identifier/literal injection risk in generated metadata SQL.
  • Community / Local / Pro boundary: Community Redshift plugin only; Local and Pro consume the Community plugin behavior without product-specific code changes.
  • Backward compatibility: Existing valid unquoted identifiers retain conditional behavior; metadata DDL keeps always-quoted names and now preserves embedded and boundary delimiters exactly.

Reviewer map

  • Start here: RedshiftIdentifierProcessor, then RedshiftMetaData.buildShowCreateTableSql and RedshiftIdentifierProcessorTest.
  • Failure condition: Redshift diverges from PostgreSQL quoting, quote/remove loses raw text, schema omission creates malformed qualification, or metadata names escape the quoted identifier boundary.
  • Rollback or disable path: Revert this PR; no migration or persisted-data rollback is required.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: Substantial AI-assisted maintainer revision and test expansion; all final changes were source-reviewed and verified with the commands above.

HandSonic and others added 5 commits July 29, 2026 18:37
…r maintainer review (OtterMind#1914)

- new RedshiftIdentifierProcessor (SPI ISQLIdentifierProcessor): quoteIdentifier
  with double-quote doubling, escapeString with single-quote doubling
- RedshiftMetaData overrides getSQLIdentifierProcessor(); SHOW CREATE TABLE
  call site uses RedshiftIdentifierProcessor.INSTANCE
- RedshiftSqlEscapes removed; tests migrated (9 green)
…uote for DDL paths (OtterMind#1914)

- quoteIdentifier(String) is conditional again: null/blank passthrough,
  valid plain identifiers returned unquoted, otherwise wrapped with
  double quotes after stripping one pair and doubling embedded quotes
- new quoteIdentifierAlways(String) for DDL-generation sites;
  buildShowCreateTableSql uses it (was RedshiftSqlEscapes.quoteIdentifier)
- quoteIdentifierIgnoreCase keeps the always-quote SPI variant meaning;
  versioned overload delegates to quoteIdentifier(String)
- tests cover both conditional and always behaviors incl. null passthrough
Reuse the verified PostgreSQL processor, preserve raw identifier round trips, and handle optional SHOW CREATE TABLE schema qualification.

Co-authored-by: HandSonic <8078023+handsonic@users.noreply.github.com>
@openai0229
openai0229 force-pushed the fix/sqli2-redshift branch from fc66ef6 to f236b4f Compare July 29, 2026 10:38

@openai0229 openai0229 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer review complete. Redshift now reuses the verified PostgreSQL identifier contract, preserves exact quote/remove round trips, and passes the clean 9-module reactor with all 182 tests green.

@openai0229
openai0229 merged commit 4984294 into OtterMind:main Jul 29, 2026
19 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Security: 34 SQL Injection Vulnerabilities in Database Plugins

2 participants